package com.xul.crowd.controller;

import com.xul.crowd.service.ProjectService;
import com.xul.crowd.util.ResultEntity;
import com.xul.entity.vo.DetailProjectVO;
import com.xul.entity.vo.PortalTypeVO;
import com.xul.entity.vo.ProjectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xul
 * @create 2021-07-30 21:13
 */

@RestController
public class ProjectProviderController {

    @Autowired
    private ProjectService projectService;

    /**
     * 将所有信息和会员的id一起保存到数据库的各各表中 给project远程调用
     *
     * @param projectVO
     * @param memberId
     * @return
     */
    @RequestMapping("save/project/vo/remote")
    public ResultEntity<String> saveProjectVORemote(@RequestBody ProjectVO projectVO, @RequestParam("memberId") Integer memberId) {
        try {
            projectService.saveProject(projectVO, memberId);
            return ResultEntity.successWithData();
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }

    /**
     * 查询到相应的分类t_project信息数据 给auth远程调用
     *
     * @return
     */
    @RequestMapping("get/portal/type/project/data/remote")
    public ResultEntity<List<PortalTypeVO>> getPortalTypeProjectDataRemote() {
        try {
            List<PortalTypeVO> portalTypeVOList = projectService.getPortalTypeVO();
            return ResultEntity.successWithData(portalTypeVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }

    /**
     * 根据projectId查询出详情信息 包括回报数据 头图数据 三表关联 给project远程调用
     *
     * @param projectId
     * @return
     */
    @RequestMapping("get/project/detail/remote/{projectId}")
    public ResultEntity<DetailProjectVO> getDetailProjectVORemote(@PathVariable("projectId") Integer projectId) {
        try {
            DetailProjectVO detailProjectVO = projectService.getDetailProjectVO(projectId);
            return ResultEntity.successWithData(detailProjectVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }
}
